﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;

namespace SaveAvailableData
{
    public partial class MainService : ServiceBase
    {
        public MainService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            System.Timers.Timer timer = new System.Timers.Timer(10000); //间隔1秒  
            timer.AutoReset = true;  
            timer.Enabled = true;     
            timer.Elapsed += new System.Timers.ElapsedEventHandler(WriteSomething);  
            timer.Start(); 
        }
 
        private void WriteSomething(object source, System.Timers.ElapsedEventArgs e)  
        {
            System.IO.File.AppendAllText("d:\\test.date.txt",string.Format("开始时间为：{0};\r\n",DateTime.Now));
        }  

        protected override void OnStop()
        {
            base.Stop();
        }
        protected override void OnPause()
        {
            base.OnPause();
        }
    }
}
